<div class="form">


<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'firms-form',
	'enableAjaxValidation' => false,
  	'htmlOptions'=>array('enctype' => 'multipart/form-data'),
));
?>

	<p class="note">
		<?php echo AdminModule::t('Поля помеченные '); ?> <span class="required">*</span> <?php echo AdminModule::t('являются обязательными'); ?>.
	</p>

	<?php echo $form->errorSummary($model); ?>
		<div class="row">
		<?php echo $form->labelEx($model,'hidden'); ?>
		<?php echo $form->dropDownList($model, 'hidden', array('0' => AdminModule::t('Нет'), '1' => AdminModule::t('Да'))); ?>
		<?php echo $form->error($model,'hidden'); ?>
		</div><!-- row -->		
		<div class="row">
		<?php echo $form->labelEx($model,'active'); ?>
		<?php echo $form->dropDownList($model, 'active', array('1' => AdminModule::t('Да'), '0' => AdminModule::t('Нет'))); ?>
		<?php echo $form->error($model,'active'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'processed'); ?>
		<?php echo $form->dropDownList($model, 'processed', array('0' => AdminModule::t('Нет'), '1' => AdminModule::t('Да'))); ?>
		<?php echo $form->error($model,'processed'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'user_id'); ?>
		<?php echo $form->dropDownList($model, 'user_id', GxHtml::listDataEx(Users::model()->active()->findAllAttributes(null, true))); ?>
		<?php echo $form->error($model,'user_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'firm_tmpl_id'); ?>
		<?php echo $form->dropDownList($model, 'firm_tmpl_id', GxHtml::listDataEx(FirmTmpls::model()->visible()->findAllAttributes(null, true))); ?>
		<?php echo $form->error($model,'firm_tmpl_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model, 'title', array('maxlength' => 255)); ?>
		<?php echo $form->error($model,'title'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model, 'description',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'description'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'service_type'); ?>
		<?php  
            echo $form->dropDownList($model, 'service_type', Controller::getServiceTypes(),
            array(
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'update'=>'#dropdown_rubrics',
                    'data'=>array('service_type'=>'js:this.value', 'pkey'=>'service_type', 'model'=>'Rubrics', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                    'success' => 'function(html) {
                            jQuery("#dropdown_rubrics").html(html);
                            jQuery("#dropdown_rubrics").change();
                    }'                      
                )
            ));
        ?>
		<?php echo $form->error($model,'service_type'); ?>
		</div><!-- row -->        
        
        
        
		<div class="row">
        <?php $service_type = (null != $model->service_type) ? $model->service_type : 0; ?>
		<?php echo $form->labelEx($model,'rubric_id'); ?>
		<?php echo $form->dropDownList($model, 'rubric_id', GxHtml::listDataEx(Rubrics::model()->visible()->servicetype($service_type)->findAllAttributes(null, true)),
            array(
                'id'=>'dropdown_rubrics',
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'data'=>array('rubric_id'=>'js:this.value', 'pkey'=>'rubric_id', 'model'=>'Categories', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
					'update'=>'#dropdown_categories',
                )
            )
		); ?>
		<?php echo $form->error($model,'rubric_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'category_id'); ?>
		<?php 
			$rubric_id = 0 < $model->rubric_id ? $model->rubric_id : Yii::app()->params['default_rubric_id'];
			echo $form->dropDownList($model, 'category_id', 
				GxHtml::listDataEx(Categories::model()->visible()->rubric_id($rubric_id)->servicetype($service_type)->findAllAttributes(null, true)), 
				array('id'=>'dropdown_categories')
			);
		?>
		<?php echo $form->error($model,'category_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'country_id'); ?>
		<?php 
            echo $form->dropDownList($model, 'country_id', GxHtml::listDataEx(Countries::model()->visible()->findAllAttributes(null, true)),
            array(
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'data'=>array('country_id'=>'js:this.value', 'pkey'=>'country_id', 'model'=>'Regions', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                    'success' => 'function(html) {
                            jQuery("#dropdown_regions").html(html);
                            jQuery("#dropdown_regions").change();
                    }'                    
                )
            ));
        ?>
		<?php echo $form->error($model,'country_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'region_id'); ?>
		<?php 
			$country_id = 0 < $model->country_id ? $model->country_id : Yii::app()->params['default_country_id'];
			echo $form->dropDownList($model, 'region_id', 
				GxHtml::listDataEx(Regions::model()->visible()->findAllAttributes(null, true, 'hidden = 0 AND country_id = :cid', array(':cid' => $country_id))), 
				array(
                    'id'=>'dropdown_regions',
                    'ajax' => array(
                        'type'=>'POST', //request type
                        'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                        'update'=>'#dropdown_cities', 
                        'data'=>array('region_id'=>'js:this.value', 'pkey'=>'region_id', 'model'=>'Cities', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                    ),/*
                    'onchange'=>  GxHtml::ajax(array('type'=>'POST',
                        'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                        'update'=>'#dropdown_cities', 
                        'data'=>array('region_id'=>'js:this.value', 'pkey'=>'region_id', 'model'=>'Cities', 'ovkey'=>'id', 'olkey' => 'name', 'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')),
                    )),*/
                )
			);         
        ?>
		<?php echo $form->error($model,'region_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'city_id'); ?>
		<?php 
			$region_id = 0 < $model->region_id ? $model->region_id : Yii::app()->params['default_region_id'];
			echo $form->dropDownList($model, 'city_id', 
				GxHtml::listDataEx(Cities::model()->visible()->findAllAttributes(null, true, 'hidden = 0 AND region_id = :rid', array(':rid' => $region_id))), 
				array('id'=>'dropdown_cities')
			);                 
            
        ?>
		<?php echo $form->error($model,'city_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'address'); ?>
		<?php echo $form->textArea($model, 'address',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'address'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'zip'); ?>
		<?php echo $form->textField($model, 'zip', array('maxlength' => 6)); ?>
		<?php echo $form->error($model,'zip'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'email'); ?>
		<?php echo $form->textField($model, 'email', array('maxlength' => 100)); ?>
		<?php echo $form->error($model,'email'); ?>
		</div><!-- row -->        
		<div class="row">
		<?php echo $form->labelEx($model,'contact_fio'); ?>
		<?php echo $form->textField($model, 'contact_fio', array('maxlength' => 100)); ?>
		<?php echo $form->error($model,'contact_fio'); ?>
		</div><!-- row -->        
		<div class="row">
		<?php echo $form->labelEx($model,'phone'); ?>
		<?php echo $form->textField($model, 'phone', array('maxlength' => 30)); ?>
		<?php echo $form->error($model,'phone'); ?>
		</div><!-- row -->        
		<div class="row">
		<?php echo $form->labelEx($model,'fax'); ?>
		<?php echo $form->textField($model, 'fax', array('maxlength' => 30)); ?>
		<?php echo $form->error($model,'fax'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'logo'); ?>
		<?php if ('' != $model->logo): ?>
			<div id="img_block">
				<?php echo GxHtml::image($this->getFirmImgSrc($model->logo, 'firms_img_logo'), 'logo', array());
				$imgajax = array(
					'dataType'=>'json',
					'success'=>'js:function(data,status){
						if ("success" == data) {
							$("#img_block").html("");
						}
					}'
				);			 
				?>
				<?php echo GxHtml::ajaxLink(AdminModule::t('Удалить логотип'), $this->createUrl('/admin/firms/deletelogo', array('id'=>$model->id)), $imgajax); ?>
			</div>
		<?php endif;?>
		<?php echo $form->activeFileField($model, 'logo'); ?>
		<?php echo $form->error($model,'logo'); ?>
		</div><!-- row -->        
        
<?php
echo GxHtml::submitButton(AdminModule::t('Сохранить'));
$this->endWidget();
?>
</div><!-- form -->